<template>
		<div class="regist-box">
			<div class="regist-content">
				<div class="regist-form">
					<div class="rf-btn">
						<span class="rf-per" :class="[state == 'per'? 'cur': '']" @click="loginBtn('per')">个人登录</span>
						<span class="rf-com" :class="[state == 'com'? 'cur': '']" @click="loginBtn('com')">公司登录</span>
					</div>
					<!-- 个人登录 -->
					<div id="pro-login-box" class="per-box" v-if="state == 'per'">
						<div class="per-two">
							<div class="pub-input">
								<span class="pub-input-title">手机号码:</span>
								<input type="text" class="pub-inputbox" v-model="phone">
							</div>
							<div class="pub-input">
								<span class="pub-input-title">登录密码:</span>
								<input type="password" class="pub-inputbox" v-model="password">
							</div>
							<span class="per-one-btn" @click="login">个人登录</span>
							<div class="other-per">
            		<router-link tag='a' :to="'/regist'" style="margin-right:10px;">还没账号？<span>立即注册></span></router-link>
								<!-- <a href="">忘记密码</a> -->
							</div>
						</div>
					</div>
					<!-- 公司注册 -->
					<div id="com-login-box" class="cop-box" v-if="state == 'com'">
						<div class="per-two">
							<div class="pub-input">
								<span class="pub-input-title">手机号码:</span>
								<input type="text" class="pub-inputbox" v-model="phone2">
							</div>
							<div class="pub-input">
								<span class="pub-input-title">登录密码:</span>
								<input type="password" class="pub-inputbox" v-model="password2">
							</div>
							<span class="per-one-btn" @click="login2">公司登录</span>
							<div class="other-per">
            		<router-link tag='a' :to="'/regist'" style="margin-right:10px;">还没账号？<span>立即注册></span></router-link>
								<!-- <a href="">忘记密码</a> -->
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
</template>

<script>
import $ from 'jquery'
export default {
  data () {
    return {
    	phone: '',
    	password: '',
    	phone2: '',
    	password2: '',
    	state: 'per'
    }
  },
  methods: {
  	loginBtn: function (key) {
  		this.state = key
  	},
  	login () {
  		var that = this
  		that.$axios.request('/Account/Login', {
  			Phone: that.phone,
  			Password: that.password
  		})
  			.then((res) => {
  				if (res.code === 0) {
  					that.$store.commit('islogin', 'Personal')
  					that.$router.push({
  						name: 'personalCenter'
  					})
  				}
  			})
  	},
  	login2 () {
  		var that = this
  		$.ajax({
        url: that.$axios.link + '/Account/Login',
        type: 'get',
        data: {
          Phone: that.phone2,
          PassWord: that.password2
        },
        xhrFields: {
          withCredentials: true
        },
        dataType: 'jsonp',
        success: function (data) {
          if (data.code === 0) {
          	that.$axios.alert('登录成功', '提示', function () {
          		window.location.href = that.$axios.link2 +'/#/inforAdd'
          	}) 
          }
          if (data.code === -1) {
            that.$axios.messageTwo(data.data, '提示')
          }
        }
      })
  	}
  },
  mounted () {
  }
}
</script>